summaryrefslogtreecommitdiff
path: root/src/explicitsimulation.h
blob: ebddd6289376997691d824417ae09c2ffd890954 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef GENETIC_EXPLICIT_SIMULATION_H
#define GENETIC_EXPLICIT_SIMULATION_H

#include "genetic/population.h"
#include "genetic/config.h"

namespace Genetic
{
	class Operator;
	class FitnessFunction;

	class ExplicitSimulation
	{
	public:
		ExplicitSimulation( Operator *pOper, FitnessFunction *pFunc,
				int iPopSize, float fKeep, float fRandom, bool bKeepBest=true );
		virtual ~ExplicitSimulation();

		void timestep();

		Genetic::PhenotypeId selectWeighted();

		double getMinFitness() const { return dMinFitness; }
		double getMaxFitness() const { return dMaxFitness; }

	protected:
		void updateFitness();

	protected:
		Population xPop;
		Operator *pOper;
		FitnessFunction *pFunc;

	private:
		int iPopSize;
		float fKeep;
		float fRandom;
		bool bKeepBest;
		typedef Bu::Hash<Genetic::PhenotypeId, double> FitnessHash;
		FitnessHash hFitness;
		double dMinFitness;
		double dMaxFitness;
		double dTotalFitness;
		PhenotypeId uMaxFitness;
	};
};

#endif